#include "SQLInterface.h"
#include "Database.h"
#include "../Defines.h"
#include "Tuple.h"
#include "Private/sql.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


// TODO: this could definitely be improved...
result_type SQL_insert_list(node_t* list)
{
    result_type result = SUCCESS;
    for(list = list; list != NULL && result == SUCCESS; list = list->next)
    {
        result = SQL_insert((tuple_t*)(list->element));
    }
    return result;
}

result_type SQL_insert(tuple_t* tuple)
{
    result_type result = insertData(tuple);
    freeTuple(tuple);
    return result;
}

node_t* SQL_select(tuple_t* matchingVals)
{
    node_t* result = readData(matchingVals);
    freeTuple(matchingVals);
    return result;
}
/*
result_type SQL_update(tuple_t* tuple)
{
    tuple_t* selectTuple;
    node_t* selectResult;
    // only supported for a few tables...
    switch(tuple->table)
    {
        case TABLE_STOCK_STATS:
            selectTuple = initTuple(TABLE_STOCK_STATS);
            selectTuple->params[STOCK_STATS_PARAM_SYMBOL] = malloc(strlen((char*)(tuple->params[STOCK_STATS_PARAM_SYMBOL])) + 1);
            selectTuple->params[STOCK_STATS_PARAM_CORRELATION_LENGTH] = malloc(strlen((char*)(tuple->params[STOCK_STATS_PARAM_CORRELATION_LENGTH])) + 1);
            strcpy((char*)(selectTuple->params[STOCK_STATS_PARAM_SYMBOL]),
                   (char*)(tuple->params[STOCK_STATS_PARAM_SYMBOL]));
            strcpy((char*)(selectTuple->params[STOCK_STATS_PARAM_CORRELATION_LENGTH]),
                   (char*)(tuple->params[STOCK_STATS_PARAM_CORRELATION_LENGTH]));
            selectResult = SQL_select(selectTuple);
            return updateData
            break;
            ...
        default:
            return GENERAL_ERROR;
    }

}*/


/*
int getNumParams(TableID table)
{
    switch(table)
    {
        case TABLE_STOCK_DATA:
            return 7;
        default:
            return 0;
    }
}*/
